// pages/mine/mine.js
var com = require("../../utils/comm.js")
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ["商家中心", "技师中心"],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    
    username: '',
    adminer: '',
  },

  salerinfo: function (e) {
    console.log("com.authjust()=" + com.authjust(1))
    com.authjust(1)
    var x = com.authjust(1);
    if (x) {
      wx.navigateTo({
        url: '/pages/salerinfo/salerinfo',
      })
    } else {
    }
  },
  servicePrice: function (e) {
    var x = com.authjust(1);
    if (x) {
      wx.navigateTo({
        url: '/pages/servicePrice/servicePrice',
      })
    }
  },
  rebates: function(e){
    var x = com.authjust(1);
    if(x){
      wx.navigateTo({
        url: '/pages/rebates/rebates',
      })
    }
  },
  passwordupd: function (e) {
    console.log("com.authjust()=" + com.authjust(1))
    com.authjust(1)
    var x = com.authjust(1);
    if (x) {
      wx.navigateTo({
        url: '/pages/passwordupd/passwordupd',
      })
    } else {
    }
  },

  distrubution: function (e) {
    console.log("com.authjust()=" + com.authjust(1))
    com.authjust(1)
    var x = com.authjust(1);
    if (x) {
      wx.navigateTo({
        url: '/pages/distrubution/distrubution',
      })
    } else {
    }
  },

  loginOut: () => {
    wx.clearStorageSync();
    wx.reLaunch({
      url: '/pages/login/loginnew/login'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });

    var admin = wx.getStorageSync("usertype");
    console.log(admin);
    that.setData({
      username: wx.getStorageSync('userName'),
      adminer: wx.getStorageSync('adminer')
    })

    if (admin == '4'){
      that.setData({
        activeIndex:0
      })
    }else if(admin =='5'){
      that.setData({
        activeIndex: 1,
        sliderOffset: 180
      })
    }


  },

  tabClick: function(e) {
    wx.showToast({
      title: "抱歉！您的权限无法使用该功能！",
      icon: 'none',
      duration: 2000
    });
  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})